/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k1(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k1_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->prec = 8;
	g->id = 1;
	g->od = 1;
	g->irep = 1;
	g->orep = 1;
	g->in.bpch[0] = 8;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 8;
	g->in.pint = 1;
	g->out.bpch[0] = 8;
	g->out.chi[0] = 1;
	g->out.bpv[0] = 8;
	g->out.pint = 1;
	g->opt = 17;
	g->itres = 255;
	g->stres = 1;
	g->kkeys[0] = 67;
	g->kkeys[1] = 111;
	g->kkeys[2] = 112;
	g->kkeys[3] = 121;
	g->kkeys[4] = 114;
	g->kkeys[5] = 105;
	g->kkeys[6] = 103;
	g->kkeys[7] = 104;
	g->kkeys[8] = 116;
	g->kkeys[9] = 32;
	g->kkeys[10] = 50;
	g->kkeys[11] = 48;
	g->kkeys[12] = 48;
	g->kkeys[13] = 52;
	g->kkeys[14] = 32;
	g->kkeys[15] = 71;
	g->kkeys[16] = 114;
	g->kkeys[17] = 97;
	g->kkeys[18] = 101;
	g->kkeys[19] = 109;
	g->kkeys[20] = 101;
	g->kkeys[21] = 32;
	g->kkeys[22] = 87;
	g->kkeys[23] = 46;
	g->kkeys[24] = 32;
	g->kkeys[25] = 71;
	g->kkeys[26] = 105;
	g->kkeys[27] = 108;
	g->kkeys[28] = 108;
	g->kdesc[0] = 49;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kname[0] = 105;
	g->kname[1] = 109;
	g->kname[2] = 100;
	g->kname[3] = 105;
	g->kname[4] = 95;
	g->kname[5] = 107;
	g->kname[6] = 49;
	t->it_ix = 1;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->we_ab = 9;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_cd = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fs = 8;
	t->im_fv = 4;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_ts = 1;
	t->ot_bits[0] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k2(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k2_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[6] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k3(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k3_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 8;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 8;
	g->in.bpch[2] = 8;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 8;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[6] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->we_es = 2;
	t->vo_ab = 16;
	t->vo_es = 2;
	t->vo_eo = 2;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k4(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k4_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[6] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k5(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k5_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 8;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 8;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[6] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k6(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k6_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[6] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k7(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k7_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 8;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 8;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[6] = 55;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k8(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k8_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 8;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 8;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[6] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k9(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k9_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 8;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 8;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[6] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k10(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k10_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 8;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[6] = 49;
	g->kname[7] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k11(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k11_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 8;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 8;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k12(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k12_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 8;
	g->in.chi[9] = 10;
	g->in.bpv[9] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k13(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k13_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.bpch[1] = 8;
	g->out.chi[1] = 3;
	g->out.bpv[1] = 8;
	g->out.bpch[2] = 8;
	g->out.chi[2] = 3;
	g->out.bpv[2] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[1] = 8;
	t->ot_bits[2] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k14(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k14_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[7] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k15(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k15_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k16(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k16_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k17(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k17_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k18(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k18_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k19(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k19_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k20(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k20_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[6] = 50;
	g->kname[7] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k21(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k21_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k22(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k22_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k23(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k23_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k24(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k24_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k25(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k25_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.bpch[3] = 8;
	g->out.chi[3] = 4;
	g->out.bpv[3] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 53;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[3] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k26(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k26_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[7] = 54;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k27(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k27_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k28(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k28_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k29(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k29_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k30(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k30_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[6] = 51;
	g->kname[7] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k31(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k31_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 49;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k32(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k32_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k33(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k33_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k34(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k34_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k35(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k35_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k36(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k36_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k37(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k37_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.bpch[4] = 8;
	g->out.chi[4] = 5;
	g->out.bpv[4] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 55;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[4] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k38(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k38_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k39(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k39_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k40(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k40_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[6] = 52;
	g->kname[7] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k41(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k41_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k42(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k42_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k43(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k43_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 51;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k44(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k44_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k45(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k45_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k46(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k46_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k47(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k47_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k48(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k48_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k49(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k49_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.bpch[5] = 8;
	g->out.chi[5] = 6;
	g->out.bpv[5] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 57;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[5] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k50(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k50_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[6] = 53;
	g->kname[7] = 48;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k51(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k51_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k52(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k52_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k53(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k53_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 27;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k54(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k54_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k55(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k55_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k56(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k56_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k57(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k57_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k58(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k58_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k59(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k59_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k60(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k60_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[6] = 54;
	g->kname[7] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k61(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k61_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.bpch[6] = 8;
	g->out.chi[6] = 7;
	g->out.bpv[6] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 49;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[6] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k62(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k62_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[7] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k63(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k63_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k64(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k64_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k65(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k65_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k66(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k66_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k67(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k67_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k68(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k68_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k69(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k69_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k70(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k70_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[6] = 55;
	g->kname[7] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k71(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k71_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k72(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k72_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 50;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k73(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k73_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.bpch[7] = 8;
	g->out.chi[7] = 8;
	g->out.bpv[7] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[7] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k74(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k74_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[7] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k75(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k75_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k76(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k76_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k77(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k77_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k78(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k78_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k79(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k79_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k80(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k80_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[6] = 56;
	g->kname[7] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k81(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k81_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 49;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k82(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k82_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 50;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k83(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k83_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k84(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k84_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 52;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k85(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k85_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.bpch[8] = 8;
	g->out.chi[8] = 9;
	g->out.bpv[8] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 53;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[8] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k86(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k86_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[7] = 54;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 84

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k87(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k87_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 84;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k88(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k88_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 19

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k89(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k89_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 19;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[7] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k90(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k90_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 127;
	g->stres = 0;
	g->kname[6] = 57;
	g->kname[7] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->we_ab = 9;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k91(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k91_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k92(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k92_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k93(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k93_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 51;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k94(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k94_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k95(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k95_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k96(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k96_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k97(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k97_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->out.bpch[9] = 8;
	g->out.chi[9] = 10;
	g->out.bpv[9] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[7] = 55;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[9] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k98(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k98_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[7] = 56;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k99(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k99_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[7] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k100(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k100_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[6] = 49;
	g->kname[7] = 48;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k101(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k101_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k102(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k102_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k103(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k103_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k104(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k104_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k105(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k105_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k106(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k106_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k107(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k107_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k108(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k108_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 56;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k109(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k109_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->irep = 3;
	g->in.bpch[0] = 16;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 16;
	g->out.chi[0] = 1;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 57;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fn = 0;
	t->im_ps = 2;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k110(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k110_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[7] = 49;
	g->kname[8] = 48;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k111(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k111_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 16;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 16;
	g->in.bpch[2] = 16;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 16;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k112(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k112_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k113(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k113_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 16;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 16;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k114(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k114_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k115(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k115_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 16;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 16;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k116(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k116_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 16;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 16;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k117(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k117_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 16;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 16;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k118(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k118_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 16;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 16;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k119(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k119_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 16;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 16;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k120(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k120_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 16;
	g->in.bpv[9] = 16;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[7] = 50;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k121(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k121_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 49;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k122(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k122_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k123(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k123_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k124(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k124_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k125(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k125_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k126(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k126_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k127(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k127_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k128(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k128_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k129(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k129_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k130(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k130_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 51;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k131(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k131_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k132(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k132_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k133(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k133_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k134(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k134_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k135(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k135_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k136(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k136_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k137(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k137_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k138(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k138_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k139(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k139_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k140(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k140_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 52;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k141(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k141_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k142(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k142_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k143(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k143_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k144(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k144_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k145(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k145_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 53;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k146(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k146_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k147(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k147_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k148(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k148_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k149(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k149_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k150(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k150_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 53;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k151(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k151_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k152(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k152_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k153(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k153_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k154(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k154_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k155(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k155_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k156(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k156_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k157(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k157_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 55;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k158(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k158_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k159(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k159_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k160(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k160_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 54;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k161(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k161_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 27;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k162(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k162_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k163(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k163_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k164(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k164_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k165(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k165_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k166(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k166_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k167(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k167_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k168(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k168_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k169(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k169_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 57;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k170(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k170_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[7] = 55;
	g->kname[8] = 48;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k171(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k171_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k172(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k172_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k173(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k173_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k174(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k174_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k175(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k175_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k176(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k176_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k177(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k177_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k178(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k178_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k179(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k179_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k180(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k180_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[7] = 56;
	g->kname[8] = 48;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k181(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k181_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 49;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k182(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k182_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k183(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k183_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k184(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k184_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k185(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k185_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k186(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k186_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k187(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k187_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k188(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k188_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k189(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k189_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k190(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k190_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k191(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k191_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k192(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k192_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k193(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k193_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k194(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k194_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 84

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k195(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k195_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 84;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k196(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k196_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 19

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k197(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k197_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 19;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k198(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k198_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 127;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->we_ab = 9;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k199(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k199_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k200(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k200_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[6] = 50;
	g->kname[7] = 48;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k201(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k201_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k202(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k202_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k203(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k203_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k204(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k204_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k205(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k205_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 53;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k206(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k206_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k207(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k207_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k208(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k208_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k209(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k209_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k210(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k210_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 49;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k211(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k211_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k212(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k212_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k213(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k213_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k214(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k214_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k215(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k215_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k216(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k216_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 56;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k217(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k217_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->irep = 1;
	g->orep = 3;
	g->in.bpch[0] = 8;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 8;
	g->out.bpch[0] = 16;
	g->out.chi[0] = 1;
	g->out.bpv[0] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 55;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fn = 0;
	t->im_ps = 2;
	t->im_pv = 1;
	t->ot_ts = 2;
	t->ot_bits[0] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k218(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k218_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k219(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k219_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 8;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 8;
	g->in.bpch[2] = 8;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 8;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k220(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k220_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 50;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k221(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k221_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 8;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 8;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k222(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k222_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k223(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k223_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 8;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 8;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k224(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k224_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 8;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 8;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k225(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k225_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 8;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 8;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k226(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k226_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 8;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k227(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k227_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 8;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 8;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k228(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 1) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k228_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 8;
	g->in.bpv[9] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k229(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k229_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.bpch[1] = 16;
	g->out.chi[1] = 3;
	g->out.bpv[1] = 16;
	g->out.bpch[2] = 16;
	g->out.chi[2] = 3;
	g->out.bpv[2] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 57;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[1] = 16;
	t->ot_bits[2] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k230(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k230_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[7] = 51;
	g->kname[8] = 48;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k231(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k231_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k232(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k232_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k233(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k233_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k234(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k234_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k235(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k235_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k236(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k236_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k237(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k237_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k238(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k238_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k239(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k239_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k240(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 3) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k240_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[7] = 52;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k241(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k241_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.bpch[3] = 16;
	g->out.chi[3] = 4;
	g->out.bpv[3] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 49;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[3] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k242(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k242_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 65535;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k243(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k243_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k244(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k244_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 39

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k245(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k245_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 39;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k246(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k246_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 181;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 30;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k247(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k247_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k248(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k248_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k249(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k249_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k250(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k250_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 53;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k251(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k251_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k252(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k252_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k253(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k253_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.bpch[4] = 16;
	g->out.chi[4] = 5;
	g->out.bpv[4] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[4] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k254(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k254_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k255(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k255_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k256(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k256_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k257(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k257_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k258(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k258_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k259(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k259_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k260(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k260_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 54;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k261(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k261_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k262(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k262_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k263(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k263_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k264(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k264_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k265(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k265_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.bpch[5] = 16;
	g->out.chi[5] = 6;
	g->out.bpv[5] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 53;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[5] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k266(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k266_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k267(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k267_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k268(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k268_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k269(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k269_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 27;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k270(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k270_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[7] = 55;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k271(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k271_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k272(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k272_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k273(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k273_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k274(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k274_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k275(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k275_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k276(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k276_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k277(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k277_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.bpch[6] = 16;
	g->out.chi[6] = 7;
	g->out.bpv[6] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 55;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[6] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k278(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k278_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k279(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k279_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k280(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k280_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[7] = 56;
	g->kname[8] = 48;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k281(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k281_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k282(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k282_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k283(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k283_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k284(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k284_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k285(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k285_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k286(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k286_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k287(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k287_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k288(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k288_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 56;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k289(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k289_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.bpch[7] = 16;
	g->out.chi[7] = 8;
	g->out.bpv[7] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 57;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[7] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k290(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k290_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 32767;
	g->stres = 0;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k291(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k291_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k292(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k292_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 1024;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->we_ab = 9;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 31

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k293(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k293_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 31;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k294(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k294_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k295(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k295_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k296(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k296_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k297(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k297_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k298(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k298_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k299(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k299_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k300(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k300_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[6] = 51;
	g->kname[7] = 48;
	g->kname[8] = 48;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k301(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k301_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.bpch[8] = 16;
	g->out.chi[8] = 9;
	g->out.bpv[8] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 49;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[8] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k302(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k302_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 50;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 84

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k303(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k303_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 84;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k304(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k304_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 19

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k305(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k305_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 19;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k306(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k306_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 127;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->we_ab = 9;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k307(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k307_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k308(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k308_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k309(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k309_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k310(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k310_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k311(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k311_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k312(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k312_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 0
   Interpolation table index bits = 8
   Simplex table max resolution = 1
   Interpolation table max resolution = 255

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned char *)((p) + 0 + (off) * 1))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 4)

/* Simplex table - get weighting/offset value */
#define SX_WO(p, v) *((unsigned short *)((p) + (v) * 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k313(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				
				imp = im_base + IM_O(ti >> 0);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0x0);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vowr;	/* Vertex offset/weight value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vowr = SX_WO(swp, 0);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vowr = SX_WO(swp, 1);	/* Read vertex offset+weighting values */
				vof = (vowr & 0x7f);	/* Extract offset value */
				vwe = (vowr >> 7);	/* Extract weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k313_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->out.bpch[9] = 16;
	g->out.bpv[9] = 16;
	g->opt = 17;
	g->itres = 255;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 51;
	t->sort = 0;
	t->it_ab = 8;
	t->it_ts = 1;
	t->ix_ab = 8;
	t->sx_ab = 0;
	t->sm_ts = 4;
	t->wo_ab = 16;
	t->wo_es = 2;
	t->vo_ab = 7;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[9] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 0
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k314(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k314_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 16383;
	g->stres = 0;
	g->kname[8] = 52;
	t->sort = 1;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 12
   Interpolation table index bits = 20
   Simplex table max resolution = 16
   Interpolation table max resolution = 101

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 16)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k315(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned int ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				
				imp = im_base + IM_O(ti >> 12);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xfff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k315_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 101;
	g->stres = 16;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 20;
	t->sx_ab = 12;
	t->sm_ts = 16;
	t->wo_es = 4;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 12
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k316(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k316_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 812;
	g->stres = 0;
	g->kname[8] = 54;
	t->sort = 1;
	t->wo_xs = 0;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Simplex table index bits       = 32
   Interpolation table index bits = 32
   Simplex table max resolution = 255
   Interpolation table max resolution = 23

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table inter & simplex indexes */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Simplex weighting table access */
#define SW_O(off) ((off) * 20)

/* Simplex table - get weighting value */
#define SX_WE(p, v) *((unsigned short *)((p) + (v) * 4 + 0))

/* Simplex table - get offset value */
#define SX_VO(p, v) *((unsigned short *)((p) + (v) * 4 + 2))

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k317(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer sw_base = (pointer)p->sw_table;
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer swp;
			pointer imp;
			{
				unsigned longlong ti;	/* Simplex+Interpolation index variable */
				
				ti  = IT_IT(it0, ip0[0]);
				ti += IT_IT(it1, ip0[1]);
				ti += IT_IT(it2, ip0[2]);
				ti += IT_IT(it3, ip0[3]);
				
				imp = im_base + IM_O(ti >> 32);		/* Extract interp. index and comp. entry */
				swp = sw_base + SW_O(ti & 0xffffffff);	/* Extract simplex index and comp. entry */
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = SX_VO(swp, 0);	/* Read vertex offset value */
				vwe = SX_WE(swp, 0);	/* Read vertex weighting value */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 1);	/* Read vertex offset value */
				vwe = SX_WE(swp, 1);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 2);	/* Read vertex offset value */
				vwe = SX_WE(swp, 2);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 3);	/* Read vertex offset value */
				vwe = SX_WE(swp, 3);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof = SX_VO(swp, 4);	/* Read vertex offset value */
				vwe = SX_WE(swp, 4);	/* Read vertex weighting value */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef SW_O
#undef SX_WE
#undef SX_VO
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k317_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 23;
	g->stres = 255;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->sort = 0;
	t->wo_xs = 1;
	t->ix_ab = 32;
	t->sx_ab = 32;
	t->sm_ts = 20;
	t->we_ab = 16;
	t->vo_ab = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k318(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k318_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->opt = 17;
	g->itres = 152;
	g->stres = 0;
	g->kname[8] = 56;
	t->sort = 1;
	t->wo_xs = 0;
	t->ix_ab = 29;
	t->we_ab = 9;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k319(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k319_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k320(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k320_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 50;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k321(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k321_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k322(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k322_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k323(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k323_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k324(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k324_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 56;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 12
   Interpolation table max resolution = 4095

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k325(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xfffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 20);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7);	/* Extract offset value */
				wo0 = (wo0 >> 3);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k325_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->prec = 16;
	g->id = 1;
	g->od = 1;
	g->irep = 3;
	g->in.bpch[0] = 16;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 16;
	g->out.chi[0] = 1;
	g->opt = 1;
	g->itres = 4095;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 12;
	t->wo_ab = 20;
	t->we_ab = 17;
	t->vo_ab = 3;
	t->vo_om = 1;
	t->im_ts = 4;
	t->im_fn = 0;
	t->im_fv = 2;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k326(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k326_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 16;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 16;
	g->in.bpch[2] = 16;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 16;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 90

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k327(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1fffff);	/* Extract offset value */
				wo3 = (wo3 >> 21);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k327_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 16;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 16;
	g->opt = 1;
	g->itres = 90;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k328(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k328_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 16;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 16;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k329(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k329_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 16;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 16;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k330(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k330_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 16;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 16;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 51;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k331(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k331_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 16;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 16;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k332(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k332_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 16;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 16;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k333(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3fffff);	/* Extract offset value */
				wo9 = (wo9 >> 22);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k333_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 16;
	g->in.bpv[9] = 16;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k334(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k334_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 52;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_fn = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k335(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k335_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k336(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k336_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k337(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k337_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k338(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k338_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k339(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k339_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k340(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k340_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 52;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k341(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k341_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k342(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k342_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k343(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k343_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 51;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k344(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k344_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k345(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k345_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k346(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k346_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k347(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k347_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k348(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k348_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k349(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k349_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k350(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k350_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 53;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k351(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k351_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 49;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k352(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k352_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 50;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k353(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k353_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k354(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k354_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k355(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k355_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k356(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k356_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k357(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k357_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k358(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k358_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k359(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k359_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->ix_es = 4;
	t->wo_es = 8;
	t->we_ab = 32;
	t->we_es = 4;
	t->we_eo = 4;
	t->vo_ab = 32;
	t->vo_es = 4;
	t->vo_eo = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k360(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k360_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[7] = 54;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k361(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k361_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 49;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 24;
	t->im_oc = 8;
	t->im_fn = 3;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k362(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k362_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k363(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k363_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k364(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k364_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k365(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k365_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k366(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k366_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k367(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k367_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k368(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k368_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k369(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k369_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k370(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k370_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[7] = 55;
	g->kname[8] = 48;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 7;
	t->im_ts = 28;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k371(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k371_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k372(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k372_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k373(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k373_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k374(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k374_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k375(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k375_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k376(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k376_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k377(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k377_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k378(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k378_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k379(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k379_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 57;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 4;
	t->im_ts = 32;
	t->im_oc = 8;
	t->im_fn = 4;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k380(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k380_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 56;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k381(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k381_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k382(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k382_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k383(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k383_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k384(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k384_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k385(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k385_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k386(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k386_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k387(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k387_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 55;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k388(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k388_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 56;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 9;
	t->im_ts = 36;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k389(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k389_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k390(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k390_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k391(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k391_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 15

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k392(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k392_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 15;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k393(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k393_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
	t->ix_ab = 23;
	t->wo_ab = 41;
	t->vo_ab = 24;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k394(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xffffff);	/* Extract offset value */
				wo7 = (wo7 >> 24);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k394_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k395(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k395_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k396(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k396_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k397(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k397_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 55;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 40;
	t->im_oc = 8;
	t->im_fn = 5;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k398(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k398_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k399(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k399_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k400(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k400_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[6] = 52;
	g->kname[7] = 48;
	g->kname[8] = 48;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k401(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k401_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k402(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k402_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k403(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k403_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k404(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k404_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k405(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k405_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 49;
	g->kdesc[12] = 54;
	g->kdesc[13] = 95;
	g->kdesc[14] = 102;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 12
   Interpolation table max resolution = 4095

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k406(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xfffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 20);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7);	/* Extract offset value */
				wo0 = (wo0 >> 3);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k406_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->in.chi[0] = 1;
	g->out.chi[0] = 1;
	g->opt = 1;
	g->itres = 4095;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 54;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 12;
	t->wo_ab = 20;
	t->we_ab = 17;
	t->vo_ab = 3;
	t->vo_om = 1;
	t->im_ts = 4;
	t->im_oc = 4;
	t->im_fn = 0;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k407(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k407_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 90

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k408(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1fffff);	/* Extract offset value */
				wo3 = (wo3 >> 21);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k408_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 90;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k409(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k409_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k410(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k410_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k411(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k411_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k412(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k412_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k413(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k413_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k414(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 1) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3fffff);	/* Extract offset value */
				wo9 = (wo9 >> 22);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k414_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kdesc[14] = 0;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k415(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k415_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_fn = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k416(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k416_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k417(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k417_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k418(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k418_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k419(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k419_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k420(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k420_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 50;
	g->kname[8] = 48;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k421(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k421_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k422(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k422_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k423(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 3) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k423_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k424(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k424_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 52;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k425(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k425_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k426(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k426_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k427(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k427_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k428(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k428_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k429(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k429_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k430(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k430_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 51;
	g->kname[8] = 48;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k431(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k431_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k432(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 4) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k432_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 50;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k433(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k433_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 51;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k434(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k434_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k435(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k435_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k436(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k436_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k437(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k437_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k438(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k438_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k439(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k439_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k440(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k440_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 52;
	g->kname[8] = 48;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k441(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 5) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k441_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k442(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k442_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 50;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 24;
	t->im_oc = 8;
	t->im_fn = 3;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k443(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k443_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k444(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k444_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k445(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k445_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k446(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k446_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k447(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k447_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k448(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k448_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k449(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k449_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k450(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 6) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k450_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[7] = 53;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k451(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k451_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 49;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 7;
	t->im_ts = 28;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k452(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k452_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k453(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k453_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k454(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k454_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k455(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k455_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k456(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k456_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k457(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k457_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k458(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k458_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k459(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 7) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k459_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k460(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k460_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->opt = 1;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[7] = 54;
	g->kname[8] = 48;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 4;
	t->im_ts = 32;
	t->im_oc = 8;
	t->im_fn = 4;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k461(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k461_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k462(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k462_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k463(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k463_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k464(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k464_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k465(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k465_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k466(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k466_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k467(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k467_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k468(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 8) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k468_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 56;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k469(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k469_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 57;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 9;
	t->im_ts = 36;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k470(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k470_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 55;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k471(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k471_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k472(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k472_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 15

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k473(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k473_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->itres = 15;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k474(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k474_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
	t->ix_ab = 23;
	t->wo_ab = 41;
	t->vo_ab = 24;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k475(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xffffff);	/* Extract offset value */
				wo7 = (wo7 >> 24);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k475_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k476(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k476_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k477(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 9) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k477_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k478(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 1 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 1, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k478_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->opt = 1;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 56;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 40;
	t->im_oc = 8;
	t->im_fn = 5;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k479(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 3 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 3, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k479_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->opt = 1;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k480(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 4 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 4, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k480_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->opt = 1;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 56;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k481(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 5 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 5, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k481_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->opt = 1;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k482(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 6 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 6, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k482_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->opt = 1;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k483(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 7 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 7, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k483_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->opt = 1;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k484(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 8 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 8, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k484_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->opt = 1;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k485(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 9 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 9, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k485_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->opt = 1;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is not supported
   Output stride is not supported
   Prefer simplex over sort algorithm
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k486(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * 10 ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += 10, op0 += 10) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k486_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->opt = 1;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 49;
	g->kdesc[12] = 54;
	g->kdesc[13] = 95;
	g->kdesc[14] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k487(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k487_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->prec = 8;
	g->id = 1;
	g->od = 1;
	g->irep = 1;
	g->orep = 1;
	g->in.bpch[0] = 8;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 8;
	g->out.bpch[0] = 8;
	g->out.chi[0] = 1;
	g->out.bpv[0] = 8;
	g->opt = 13;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 55;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->we_ab = 9;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fn = 0;
	t->im_fv = 4;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_ts = 1;
	t->ot_bits[0] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k488(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k488_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 8;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 8;
	g->in.bpch[2] = 8;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 8;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k489(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k489_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 8;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 8;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k490(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k490_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 8;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 8;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k491(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k491_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 8;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 8;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k492(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k492_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 8;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 8;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k493(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k493_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 8;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k494(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k494_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 8;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 8;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k495(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k495_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 8;
	g->in.bpv[9] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k496(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k496_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.bpch[1] = 8;
	g->out.chi[1] = 3;
	g->out.bpv[1] = 8;
	g->out.bpch[2] = 8;
	g->out.chi[2] = 3;
	g->out.bpv[2] = 8;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 54;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[1] = 8;
	t->ot_bits[2] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k497(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k497_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k498(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k498_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k499(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k499_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k500(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k500_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[6] = 53;
	g->kname[7] = 48;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k501(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k501_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k502(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k502_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k503(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k503_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k504(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k504_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k505(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k505_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.bpch[3] = 8;
	g->out.chi[3] = 4;
	g->out.bpv[3] = 8;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[3] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k506(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k506_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k507(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k507_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k508(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k508_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k509(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k509_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k510(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k510_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k511(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k511_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k512(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k512_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k513(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k513_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k514(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k514_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.bpch[4] = 8;
	g->out.chi[4] = 5;
	g->out.bpv[4] = 8;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 52;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[4] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k515(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k515_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k516(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k516_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k517(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k517_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k518(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k518_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k519(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k519_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k520(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k520_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 50;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k521(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k521_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k522(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k522_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k523(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k523_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.bpch[5] = 8;
	g->out.chi[5] = 6;
	g->out.bpv[5] = 8;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 51;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[5] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k524(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k524_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k525(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k525_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k526(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k526_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k527(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k527_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k528(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k528_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k529(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k529_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k530(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k530_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 51;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k531(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k531_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k532(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k532_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.bpch[6] = 8;
	g->out.chi[6] = 7;
	g->out.bpv[6] = 8;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 50;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[6] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k533(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k533_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k534(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k534_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k535(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k535_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k536(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k536_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k537(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k537_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k538(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k538_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k539(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k539_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k540(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k540_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[7] = 52;
	g->kname[8] = 48;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k541(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k541_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.bpch[7] = 8;
	g->out.chi[7] = 8;
	g->out.bpv[7] = 8;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[8] = 49;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[7] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k542(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k542_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k543(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k543_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k544(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k544_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k545(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k545_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k546(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k546_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k547(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k547_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k548(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k548_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k549(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k549_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k550(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k550_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.bpch[8] = 8;
	g->out.chi[8] = 9;
	g->out.bpv[8] = 8;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 56;
	g->kdesc[9] = 95;
	g->kdesc[10] = 102;
	g->kdesc[11] = 0;
	g->kname[7] = 53;
	g->kname[8] = 48;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[8] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k551(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k551_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k552(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k552_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 127;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k553(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k553_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k554(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k554_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k555(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k555_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k556(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k556_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k557(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k557_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k558(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k558_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k559(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k559_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->out.bpch[9] = 8;
	g->out.bpv[9] = 8;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 57;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[9] = 8;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k560(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k560_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 54;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k561(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k561_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k562(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k562_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k563(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k563_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k564(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k564_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k565(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k565_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k566(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k566_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k567(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k567_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 56;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k568(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k568_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->irep = 3;
	g->in.bpch[0] = 16;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 16;
	g->out.chi[0] = 1;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 56;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fn = 0;
	t->im_ps = 2;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k569(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k569_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 16;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 16;
	g->in.bpch[2] = 16;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 16;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k570(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k570_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 16;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 16;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 55;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k571(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k571_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 16;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 16;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k572(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k572_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 16;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 16;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k573(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k573_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 16;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 16;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k574(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k574_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 16;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 16;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k575(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k575_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 16;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 16;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 8
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k576(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k576_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 16;
	g->in.bpv[9] = 16;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k577(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k577_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 55;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k578(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k578_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k579(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k579_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k580(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k580_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 56;
	g->kname[8] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k581(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k581_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k582(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k582_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k583(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k583_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k584(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k584_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 8
   Output channel 0 increment = 3
   Output channel 1 bits = 8
   Output channel 1 increment = 3
   Output channel 2 bits = 8
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k585(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k585_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k586(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k586_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 54;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k587(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k587_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k588(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k588_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k589(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k589_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k590(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k590_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 57;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k591(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k591_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k592(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k592_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k593(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k593_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 8
   Output channel 0 increment = 4
   Output channel 1 bits = 8
   Output channel 1 increment = 4
   Output channel 2 bits = 8
   Output channel 2 increment = 4
   Output channel 3 bits = 8
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k594(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k594_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k595(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k595_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k596(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k596_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k597(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k597_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k598(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k598_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k599(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k599_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k600(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k600_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[6] = 54;
	g->kname[7] = 48;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k601(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k601_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k602(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k602_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 8
   Output channel 0 increment = 5
   Output channel 1 bits = 8
   Output channel 1 increment = 5
   Output channel 2 bits = 8
   Output channel 2 increment = 5
   Output channel 3 bits = 8
   Output channel 3 increment = 5
   Output channel 4 bits = 8
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k603(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k603_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k604(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k604_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 52;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k605(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k605_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k606(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k606_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k607(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k607_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k608(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k608_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k609(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k609_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k610(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k610_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k611(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k611_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 8
   Output channel 0 increment = 6
   Output channel 1 bits = 8
   Output channel 1 increment = 6
   Output channel 2 bits = 8
   Output channel 2 increment = 6
   Output channel 3 bits = 8
   Output channel 3 increment = 6
   Output channel 4 bits = 8
   Output channel 4 increment = 6
   Output channel 5 bits = 8
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k612(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k612_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k613(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k613_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 51;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k614(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k614_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k615(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k615_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k616(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k616_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k617(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k617_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k618(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k618_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k619(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k619_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k620(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k620_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 50;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 8
   Output channel 0 increment = 7
   Output channel 1 bits = 8
   Output channel 1 increment = 7
   Output channel 2 bits = 8
   Output channel 2 increment = 7
   Output channel 3 bits = 8
   Output channel 3 increment = 7
   Output channel 4 bits = 8
   Output channel 4 increment = 7
   Output channel 5 bits = 8
   Output channel 5 increment = 7
   Output channel 6 bits = 8
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k621(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k621_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 49;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k622(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k622_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 50;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k623(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k623_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k624(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k624_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k625(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k625_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k626(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k626_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k627(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k627_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k628(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k628_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k629(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k629_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 8
   Output channel 0 increment = 8
   Output channel 1 bits = 8
   Output channel 1 increment = 8
   Output channel 2 bits = 8
   Output channel 2 increment = 8
   Output channel 3 bits = 8
   Output channel 3 increment = 8
   Output channel 4 bits = 8
   Output channel 4 increment = 8
   Output channel 5 bits = 8
   Output channel 5 increment = 8
   Output channel 6 bits = 8
   Output channel 6 increment = 8
   Output channel 7 bits = 8
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k630(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k630_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[7] = 51;
	g->kname[8] = 48;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k631(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k631_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 56;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 49;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k632(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k632_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k633(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k633_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 127;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k634(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k634_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k635(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k635_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k636(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k636_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k637(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k637_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k638(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k638_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 8
   Output channel 0 increment = 9
   Output channel 1 bits = 8
   Output channel 1 increment = 9
   Output channel 2 bits = 8
   Output channel 2 increment = 9
   Output channel 3 bits = 8
   Output channel 3 increment = 9
   Output channel 4 bits = 8
   Output channel 4 increment = 9
   Output channel 5 bits = 8
   Output channel 5 increment = 9
   Output channel 6 bits = 8
   Output channel 6 increment = 9
   Output channel 7 bits = 8
   Output channel 7 increment = 9
   Output channel 8 bits = 8
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k639(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k639_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 56;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k640(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k640_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[7] = 52;
	g->kname[8] = 48;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k641(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k641_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k642(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k642_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k643(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k643_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k644(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k644_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k645(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k645_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k646(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k646_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k647(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k647_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 8
   Output channel 0 increment = 10
   Output channel 1 bits = 8
   Output channel 1 increment = 10
   Output channel 2 bits = 8
   Output channel 2 increment = 10
   Output channel 3 bits = 8
   Output channel 3 increment = 10
   Output channel 4 bits = 8
   Output channel 4 increment = 10
   Output channel 5 bits = 8
   Output channel 5 increment = 10
   Output channel 6 bits = 8
   Output channel 6 increment = 10
   Output channel 7 bits = 8
   Output channel 7 increment = 10
   Output channel 8 bits = 8
   Output channel 8 increment = 10
   Output channel 9 bits = 8
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned char *)((p) + (off) * 1))

void
imdi_k648(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned char *op0 = (unsigned char *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k648_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 56;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kdesc[14] = 0;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k649(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k649_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->irep = 1;
	g->orep = 3;
	g->in.bpch[0] = 8;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 8;
	g->out.bpch[0] = 16;
	g->out.chi[0] = 1;
	g->out.bpv[0] = 16;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 57;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->vo_om = 1;
	t->im_ts = 2;
	t->im_oc = 2;
	t->im_fn = 0;
	t->im_ps = 2;
	t->im_pv = 1;
	t->ot_ts = 2;
	t->ot_bits[0] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k650(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k650_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 8;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 8;
	g->in.bpch[2] = 8;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 8;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 53;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k651(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k651_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 8;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 8;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k652(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k652_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 8;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 8;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k653(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k653_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 8;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 8;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k654(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k654_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 8;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 8;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k655(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k655_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 8;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k656(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k656_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 8;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 8;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 2)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned short *)((p) + 0 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k657(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned short ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k657_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 8;
	g->in.bpv[9] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k658(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k658_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.bpch[1] = 16;
	g->out.chi[1] = 3;
	g->out.bpv[1] = 16;
	g->out.bpch[2] = 16;
	g->out.chi[2] = 3;
	g->out.bpv[2] = 16;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 56;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_ts = 8;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[1] = 16;
	t->ot_bits[2] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k659(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k659_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k660(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k660_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 54;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k661(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k661_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k662(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k662_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k663(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k663_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k664(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k664_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k665(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k665_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned longlong *)((p) + 0 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k666(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k666_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 16
   Interpolation table max resolution = 65535

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k667(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 16);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7f);	/* Extract offset value */
				wo0 = (wo0 >> 7);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k667_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.bpch[3] = 16;
	g->out.chi[3] = 4;
	g->out.bpv[3] = 16;
	g->itres = 65535;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 55;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 16;
	t->wo_ab = 16;
	t->vo_ab = 7;
	t->im_fn = 1;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[3] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k668(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k668_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 181

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k669(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 25);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k669_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 181;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k670(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k670_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 55;
	g->kname[8] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k671(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k671_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k672(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k672_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 12

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k673(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k673_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 12;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k674(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k674_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 8)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k675(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 26);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k675_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k676(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k676_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.bpch[4] = 16;
	g->out.chi[4] = 5;
	g->out.bpv[4] = 16;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 54;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 10;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[4] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k677(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k677_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k678(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k678_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k679(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k679_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k680(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k680_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 56;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k681(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k681_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k682(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k682_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k683(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k683_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 10)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 8 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k684(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned short ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k684_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k685(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k685_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.bpch[5] = 16;
	g->out.chi[5] = 6;
	g->out.bpv[5] = 16;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[5] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k686(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k686_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k687(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k687_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k688(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k688_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k689(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k689_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k690(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k690_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k691(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k691_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k692(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k692_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k693(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k693_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k694(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k694_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.bpch[6] = 16;
	g->out.chi[6] = 7;
	g->out.bpv[6] = 16;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 52;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_ps = 8;
	t->im_pv = 3;
	t->ot_bits[6] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k695(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k695_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k696(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k696_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k697(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k697_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k698(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k698_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k699(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k699_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k700(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k700_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[6] = 55;
	g->kname[7] = 48;
	g->kname[8] = 48;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k701(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k701_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))
#define IM_PE(p, v) *((unsigned longlong *)((p) + 8 + (v) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k702(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k702_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 50;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 15
   Interpolation table max resolution = 32767

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k703(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 17);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xff);	/* Extract offset value */
				wo0 = (wo0 >> 8);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k703_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.bpch[7] = 16;
	g->out.chi[7] = 8;
	g->out.bpv[7] = 16;
	g->itres = 32767;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 51;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 15;
	t->wo_ab = 17;
	t->vo_ab = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
	t->ot_bits[7] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 30
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k704(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 30) >> 30);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 34);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 25);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 25);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 25);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k704_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 30;
	t->wo_ab = 34;
	t->vo_ab = 25;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k705(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k705_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 55

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k706(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k706_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 55;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 28

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k707(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k707_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 28;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k708(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k708_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k709(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k709_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k710(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 26);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 26);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 26);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 26);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 26);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k710_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k711(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k711_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[8] = 49;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k712(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k712_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.bpch[8] = 16;
	g->out.chi[8] = 9;
	g->out.bpv[8] = 16;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 56;
	g->kdesc[6] = 95;
	g->kdesc[7] = 105;
	g->kdesc[8] = 49;
	g->kdesc[9] = 54;
	g->kdesc[10] = 95;
	g->kdesc[11] = 102;
	g->kdesc[12] = 0;
	g->kname[8] = 50;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 9;
	t->im_ts = 18;
	t->im_oc = 2;
	t->im_ps = 2;
	t->im_pn = 1;
	t->im_pv = 1;
	t->ot_bits[8] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k713(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k713_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 127

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k714(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k714_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 127;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k715(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k715_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k716(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k716_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 14

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k717(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k717_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 14;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
	t->ix_ab = 27;
	t->wo_ab = 37;
	t->vo_ab = 28;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k718(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k718_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k719(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k719_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 27
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 18)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 2 + (c) * 8))
#define IM_PE(p, v) *((unsigned short *)((p) + 16 + (v) * 2))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k720(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned short ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 27) >> 27);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 37);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xfffffff);	/* Extract offset value */
				wo0 = (wo0 >> 28);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xfffffff);	/* Extract offset value */
				wo1 = (wo1 >> 28);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xfffffff);	/* Extract offset value */
				wo2 = (wo2 >> 28);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xfffffff);	/* Extract offset value */
				wo3 = (wo3 >> 28);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xfffffff);	/* Extract offset value */
				wo4 = (wo4 >> 28);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xfffffff);	/* Extract offset value */
				wo5 = (wo5 >> 28);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xfffffff);	/* Extract offset value */
				wo6 = (wo6 >> 28);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xfffffff);	/* Extract offset value */
				wo7 = (wo7 >> 28);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0xfffffff);	/* Extract offset value */
				wo8 = (wo8 >> 28);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0xfffffff);	/* Extract offset value */
				wo9 = (wo9 >> 28);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k720_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 56;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kname[7] = 50;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 8
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 14
   Interpolation table max resolution = 16383

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k721(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3ffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 18);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1ff);	/* Extract offset value */
				wo0 = (wo0 >> 9);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k721_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->out.bpch[9] = 16;
	g->out.bpv[9] = 16;
	g->itres = 16383;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 49;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 14;
	t->wo_ab = 18;
	t->vo_ab = 9;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pv = 2;
	t->ot_bits[9] = 16;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 8
   Input channel 0 increment = 3
   Input channel 1 bits = 8
   Input channel 1 increment = 3
   Input channel 2 bits = 8
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 812

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k722(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k722_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 812;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 29;
	t->wo_ab = 35;
	t->vo_ab = 26;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 8
   Input channel 0 increment = 4
   Input channel 1 bits = 8
   Input channel 1 increment = 4
   Input channel 2 bits = 8
   Input channel 2 increment = 4
   Input channel 3 bits = 8
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 29
   Interpolation table max resolution = 152

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k723(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 29) >> 29);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 35);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 26);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 26);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 26);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 26);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k723_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 152;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 8
   Input channel 0 increment = 5
   Input channel 1 bits = 8
   Input channel 1 increment = 5
   Input channel 2 bits = 8
   Input channel 2 increment = 5
   Input channel 3 bits = 8
   Input channel 3 increment = 5
   Input channel 4 bits = 8
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 48

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k724(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k724_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 48;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
	t->ix_ab = 28;
	t->wo_ab = 36;
	t->vo_ab = 27;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 8
   Input channel 0 increment = 6
   Input channel 1 bits = 8
   Input channel 1 increment = 6
   Input channel 2 bits = 8
   Input channel 2 increment = 6
   Input channel 3 bits = 8
   Input channel 3 increment = 6
   Input channel 4 bits = 8
   Input channel 4 increment = 6
   Input channel 5 bits = 8
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 25

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k725(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k725_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 25;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 8
   Input channel 0 increment = 7
   Input channel 1 bits = 8
   Input channel 1 increment = 7
   Input channel 2 bits = 8
   Input channel 2 increment = 7
   Input channel 3 bits = 8
   Input channel 3 increment = 7
   Input channel 4 bits = 8
   Input channel 4 increment = 7
   Input channel 5 bits = 8
   Input channel 5 increment = 7
   Input channel 6 bits = 8
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k726(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k726_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 16;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 8
   Input channel 0 increment = 8
   Input channel 1 bits = 8
   Input channel 1 increment = 8
   Input channel 2 bits = 8
   Input channel 2 increment = 8
   Input channel 3 bits = 8
   Input channel 3 increment = 8
   Input channel 4 bits = 8
   Input channel 4 increment = 8
   Input channel 5 bits = 8
   Input channel 5 increment = 8
   Input channel 6 bits = 8
   Input channel 6 increment = 8
   Input channel 7 bits = 8
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k727(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k727_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 8
   Input channel 0 increment = 9
   Input channel 1 bits = 8
   Input channel 1 increment = 9
   Input channel 2 bits = 8
   Input channel 2 increment = 9
   Input channel 3 bits = 8
   Input channel 3 increment = 9
   Input channel 4 bits = 8
   Input channel 4 increment = 9
   Input channel 5 bits = 8
   Input channel 5 increment = 9
   Input channel 6 bits = 8
   Input channel 6 increment = 9
   Input channel 7 bits = 8
   Input channel 7 increment = 9
   Input channel 8 bits = 8
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k728(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k728_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 8;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 8
   Input channel 0 increment = 10
   Input channel 1 bits = 8
   Input channel 1 increment = 10
   Input channel 2 bits = 8
   Input channel 2 increment = 10
   Input channel 3 bits = 8
   Input channel 3 increment = 10
   Input channel 4 bits = 8
   Input channel 4 increment = 10
   Input channel 5 bits = 8
   Input channel 5 increment = 10
   Input channel 6 bits = 8
   Input channel 6 increment = 10
   Input channel 7 bits = 8
   Input channel 7 increment = 10
   Input channel 8 bits = 8
   Input channel 8 increment = 10
   Input channel 9 bits = 8
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 8
   Weight+voffset bits       = 32
   Interpolation table index bits = 28
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k729(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned char *ip0 = (unsigned char *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned char *ep = (unsigned char *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 28) >> 28);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 36);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7ffffff);	/* Extract offset value */
				wo0 = (wo0 >> 27);		/* Extract weighting value */
				vwe = 256 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7ffffff);	/* Extract offset value */
				wo1 = (wo1 >> 27);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7ffffff);	/* Extract offset value */
				wo2 = (wo2 >> 27);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7ffffff);	/* Extract offset value */
				wo3 = (wo3 >> 27);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7ffffff);	/* Extract offset value */
				wo4 = (wo4 >> 27);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7ffffff);	/* Extract offset value */
				wo5 = (wo5 >> 27);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7ffffff);	/* Extract offset value */
				wo6 = (wo6 >> 27);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7ffffff);	/* Extract offset value */
				wo7 = (wo7 >> 27);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7ffffff);	/* Extract offset value */
				wo8 = (wo8 >> 27);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7ffffff);	/* Extract offset value */
				wo9 = (wo9 >> 27);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 8) & 0xff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 24) & 0xff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova0 >> 40) & 0xff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova0 >> 56) & 0xff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova1 >> 8) & 0xff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova1 >> 24) & 0xff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova1 >> 40) & 0xff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova1 >> 56) & 0xff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova2 >> 8) & 0xff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova2 >> 24) & 0xff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k729_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 56;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 12
   Interpolation table max resolution = 4095

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k730(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xfffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 20);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7);	/* Extract offset value */
				wo0 = (wo0 >> 3);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k730_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->prec = 16;
	g->id = 1;
	g->od = 1;
	g->irep = 3;
	g->in.bpch[0] = 16;
	g->in.chi[0] = 1;
	g->in.bpv[0] = 16;
	g->out.chi[0] = 1;
	g->itres = 4095;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[7] = 51;
	g->kname[8] = 48;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 12;
	t->wo_ab = 20;
	t->we_ab = 17;
	t->vo_ab = 3;
	t->vo_om = 1;
	t->im_ts = 4;
	t->im_fn = 0;
	t->im_fv = 2;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k731(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k731_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.bpch[1] = 16;
	g->in.chi[1] = 3;
	g->in.bpv[1] = 16;
	g->in.bpch[2] = 16;
	g->in.chi[2] = 3;
	g->in.bpv[2] = 16;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 90

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k732(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1fffff);	/* Extract offset value */
				wo3 = (wo3 >> 21);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k732_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.bpch[3] = 16;
	g->in.chi[3] = 4;
	g->in.bpv[3] = 16;
	g->itres = 90;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k733(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k733_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.bpch[4] = 16;
	g->in.chi[4] = 5;
	g->in.bpv[4] = 16;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k734(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k734_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.bpch[5] = 16;
	g->in.chi[5] = 6;
	g->in.bpv[5] = 16;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k735(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k735_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.bpch[6] = 16;
	g->in.chi[6] = 7;
	g->in.bpv[6] = 16;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k736(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k736_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.bpch[7] = 16;
	g->in.chi[7] = 8;
	g->in.bpv[7] = 16;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k737(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k737_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.bpch[8] = 16;
	g->in.chi[8] = 9;
	g->in.bpv[8] = 16;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k738(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3fffff);	/* Extract offset value */
				wo9 = (wo9 >> 22);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k738_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->in.bpch[9] = 16;
	g->in.bpv[9] = 16;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k739(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k739_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 57;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_fn = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k740(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k740_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 52;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k741(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k741_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k742(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k742_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k743(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k743_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k744(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k744_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k745(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k745_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k746(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k746_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k747(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k747_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k748(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k748_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 56;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k749(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k749_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k750(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k750_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 53;
	g->kname[8] = 48;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k751(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k751_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k752(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k752_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k753(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k753_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k754(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k754_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k755(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k755_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k756(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k756_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 54;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k757(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k757_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 55;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k758(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k758_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k759(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k759_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k760(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k760_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 54;
	g->kname[8] = 48;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k761(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k761_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k762(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k762_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k763(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k763_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k764(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k764_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k765(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k765_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k766(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k766_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 54;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 24;
	t->im_oc = 8;
	t->im_fn = 3;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k767(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k767_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k768(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k768_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k769(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k769_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k770(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k770_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 55;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k771(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k771_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k772(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k772_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k773(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k773_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k774(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k774_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k775(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k775_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 53;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 7;
	t->im_ts = 28;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k776(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k776_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k777(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k777_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k778(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k778_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k779(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k779_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k780(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k780_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 56;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k781(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k781_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k782(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k782_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k783(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k783_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k784(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k784_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 52;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 4;
	t->im_ts = 32;
	t->im_oc = 8;
	t->im_fn = 4;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k785(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k785_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k786(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k786_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k787(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k787_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k788(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k788_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k789(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k789_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k790(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k790_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 57;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k791(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k791_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k792(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k792_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 50;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k793(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k793_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 51;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 9;
	t->im_ts = 36;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k794(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k794_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k795(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k795_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k796(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k796_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 15

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k797(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k797_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 15;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k798(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k798_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
	t->ix_ab = 23;
	t->wo_ab = 41;
	t->vo_ab = 24;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k799(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xffffff);	/* Extract offset value */
				wo7 = (wo7 >> 24);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k799_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k800(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k800_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[6] = 56;
	g->kname[7] = 48;
	g->kname[8] = 48;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k801(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k801_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k802(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k802_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 50;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 40;
	t->im_oc = 8;
	t->im_fn = 5;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k803(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k803_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 51;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k804(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k804_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k805(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k805_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 53;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k806(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k806_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k807(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k807_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k808(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k808_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k809(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k809_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 57;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k810(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k810_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 49;
	g->kdesc[12] = 54;
	g->kdesc[13] = 95;
	g->kdesc[14] = 102;
	g->kname[7] = 49;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 12
   Interpolation table max resolution = 4095

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k811(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0xfffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 20);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7);	/* Extract offset value */
				wo0 = (wo0 >> 3);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k811_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 1;
	g->in.chi[0] = 1;
	g->out.chi[0] = 1;
	g->itres = 4095;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 49;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 12;
	t->wo_ab = 20;
	t->we_ab = 17;
	t->vo_ab = 3;
	t->vo_om = 1;
	t->im_ts = 4;
	t->im_oc = 4;
	t->im_fn = 0;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k812(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k812_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 50;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 90

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k813(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x1fffff);	/* Extract offset value */
				wo3 = (wo3 >> 21);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k813_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 90;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k814(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k814_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 52;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k815(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k815_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k816(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k816_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k817(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k817_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k818(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k818_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 1
   Output channel 0 bits = 16
   Output channel 0 increment = 1
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 4)

/* Interpolation table - get vertex values */
#define IM_PE(p, v) *((unsigned int *)((p) + 0 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k819(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned int ova0;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x3fffff);	/* Extract offset value */
				wo9 = (wo9 >> 22);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_PE
#undef OT_E

void
imdi_k819_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kdesc[14] = 0;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k820(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k820_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 3;
	g->in.chi[0] = 1;
	g->out.chi[0] = 3;
	g->out.chi[1] = 3;
	g->out.chi[2] = 3;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 51;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[7] = 50;
	g->kname[8] = 48;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 12;
	t->im_fn = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k821(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k821_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 49;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k822(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k822_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 50;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k823(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k823_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k824(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k824_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k825(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k825_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 53;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k826(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k826_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k827(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k827_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 3
   Output channel 0 bits = 16
   Output channel 0 increment = 3
   Output channel 1 bits = 16
   Output channel 1 increment = 3
   Output channel 2 bits = 16
   Output channel 2 increment = 3
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 12)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 8 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k828(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned int ova1;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k828_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 51;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k829(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k829_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 4;
	g->in.chi[0] = 1;
	g->out.chi[0] = 4;
	g->out.chi[1] = 4;
	g->out.chi[2] = 4;
	g->out.chi[3] = 4;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 52;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 57;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->vo_ab = 4;
	t->vo_om = 2;
	t->im_ts = 16;
	t->im_oc = 8;
	t->im_fn = 2;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k830(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k830_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[7] = 51;
	g->kname[8] = 48;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k831(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k831_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 49;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k832(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k832_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 17

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k833(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k833_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 17;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k834(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k834_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 52;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k835(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k835_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 53;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k836(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x3fffff);	/* Extract offset value */
				wo6 = (wo6 >> 22);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x3fffff);	/* Extract offset value */
				wo7 = (wo7 >> 22);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x3fffff);	/* Extract offset value */
				wo8 = (wo8 >> 22);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k836_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 4
   Output channel 0 bits = 16
   Output channel 0 increment = 4
   Output channel 1 bits = 16
   Output channel 1 increment = 4
   Output channel 2 bits = 16
   Output channel 2 increment = 4
   Output channel 3 bits = 16
   Output channel 3 increment = 4
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 16)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k837(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k837_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 52;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 55;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k838(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k838_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 5;
	g->in.chi[0] = 1;
	g->out.chi[0] = 5;
	g->out.chi[1] = 5;
	g->out.chi[2] = 5;
	g->out.chi[3] = 5;
	g->out.chi[4] = 5;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 53;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 56;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 20;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k839(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k839_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 57;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k840(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k840_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[7] = 52;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k841(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k841_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 49;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k842(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k842_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k843(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k843_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k844(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k844_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k845(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k845_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 53;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 5
   Output channel 0 bits = 16
   Output channel 0 increment = 5
   Output channel 1 bits = 16
   Output channel 1 increment = 5
   Output channel 2 bits = 16
   Output channel 2 increment = 5
   Output channel 3 bits = 16
   Output channel 3 increment = 5
   Output channel 4 bits = 16
   Output channel 4 increment = 5
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 20)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 16 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k846(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned int ova2;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k846_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 53;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 54;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k847(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k847_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 6;
	g->in.chi[0] = 1;
	g->out.chi[0] = 6;
	g->out.chi[1] = 6;
	g->out.chi[2] = 6;
	g->out.chi[3] = 6;
	g->out.chi[4] = 6;
	g->out.chi[5] = 6;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 54;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 55;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 3;
	t->im_ts = 24;
	t->im_oc = 8;
	t->im_fn = 3;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 26
   Interpolation table max resolution = 406

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k848(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 26) >> 26);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 38);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1fffff);	/* Extract offset value */
				wo0 = (wo0 >> 21);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x1fffff);	/* Extract offset value */
				wo1 = (wo1 >> 21);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x1fffff);	/* Extract offset value */
				wo2 = (wo2 >> 21);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k848_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 406;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 56;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 26;
	t->wo_ab = 38;
	t->vo_ab = 21;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k849(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k849_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 57;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 32

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k850(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k850_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 32;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[7] = 53;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k851(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x3fffff);	/* Extract offset value */
				wo4 = (wo4 >> 22);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x3fffff);	/* Extract offset value */
				wo5 = (wo5 >> 22);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k851_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k852(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k852_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 50;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 8

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k853(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k853_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 51;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k854(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k854_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 6
   Output channel 0 bits = 16
   Output channel 0 increment = 6
   Output channel 1 bits = 16
   Output channel 1 increment = 6
   Output channel 2 bits = 16
   Output channel 2 increment = 6
   Output channel 3 bits = 16
   Output channel 3 increment = 6
   Output channel 4 bits = 16
   Output channel 4 increment = 6
   Output channel 5 bits = 16
   Output channel 5 increment = 6
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 5

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 24)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k855(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			unsigned longlong wo9;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it9, ip0[9]);
				wo9   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
					XFR(wot, wo9);
					CJ(wo8, wot, shs9);
					XFR(wo9, wo8);
					CXJ(wo7, wot, wo8, shs9);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs9);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs9);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs9);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs9);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs9);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs9);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs9);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs9:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo9 & 0x7fffff);	/* Extract offset value */
				wo9 = (wo9 >> 23);		/* Extract weighting value */
				vwe = wo8 - wo9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k855_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 5;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 54;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k856(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k856_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 7;
	g->in.chi[0] = 1;
	g->out.chi[0] = 7;
	g->out.chi[1] = 7;
	g->out.chi[2] = 7;
	g->out.chi[3] = 7;
	g->out.chi[4] = 7;
	g->out.chi[5] = 7;
	g->out.chi[6] = 7;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 55;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 54;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->vo_ab = 5;
	t->vo_om = 7;
	t->im_ts = 28;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k857(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k857_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 55;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k858(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k858_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 56;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k859(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k859_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k860(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k860_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[7] = 54;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k861(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k861_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k862(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k862_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k863(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k863_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 51;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 7
   Output channel 0 bits = 16
   Output channel 0 increment = 7
   Output channel 1 bits = 16
   Output channel 1 increment = 7
   Output channel 2 bits = 16
   Output channel 2 increment = 7
   Output channel 3 bits = 16
   Output channel 3 increment = 7
   Output channel 4 bits = 16
   Output channel 4 increment = 7
   Output channel 5 bits = 16
   Output channel 5 increment = 7
   Output channel 6 bits = 16
   Output channel 6 increment = 7
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 28)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 24 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k864(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned int ova3;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k864_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 55;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 52;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 11
   Interpolation table max resolution = 2048

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k865(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x1fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 21);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xf);	/* Extract offset value */
				wo0 = (wo0 >> 4);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k865_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 8;
	g->in.chi[0] = 1;
	g->out.chi[0] = 8;
	g->out.chi[1] = 8;
	g->out.chi[2] = 8;
	g->out.chi[3] = 8;
	g->out.chi[4] = 8;
	g->out.chi[5] = 8;
	g->out.chi[6] = 8;
	g->out.chi[7] = 8;
	g->itres = 2048;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 56;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 53;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 11;
	t->wo_ab = 21;
	t->we_ab = 17;
	t->vo_ab = 4;
	t->vo_om = 4;
	t->im_ts = 32;
	t->im_oc = 8;
	t->im_fn = 4;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k866(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k866_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 54;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k867(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k867_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k868(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k868_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 56;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k869(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k869_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k870(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k870_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[7] = 55;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k871(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k871_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 49;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 6

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k872(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			unsigned longlong wo8;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it8, ip0[8]);
				wo8   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
					XFR(wot, wo8);
					CJ(wo7, wot, shs8);
					XFR(wo8, wo7);
					CXJ(wo6, wot, wo7, shs8);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs8);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs8);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs8);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs8);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs8);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs8);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs8:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo8 & 0x7fffff);	/* Extract offset value */
				wo8 = (wo8 >> 23);		/* Extract weighting value */
				vwe = wo7 - wo8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k872_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 6;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 8
   Output channel 0 bits = 16
   Output channel 0 increment = 8
   Output channel 1 bits = 16
   Output channel 1 increment = 8
   Output channel 2 bits = 16
   Output channel 2 increment = 8
   Output channel 3 bits = 16
   Output channel 3 increment = 8
   Output channel 4 bits = 16
   Output channel 4 increment = 8
   Output channel 5 bits = 16
   Output channel 5 increment = 8
   Output channel 6 bits = 16
   Output channel 6 increment = 8
   Output channel 7 bits = 16
   Output channel 7 increment = 8
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 32)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k873(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k873_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 56;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 51;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k874(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k874_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 9;
	g->in.chi[0] = 1;
	g->out.chi[0] = 9;
	g->out.chi[1] = 9;
	g->out.chi[2] = 9;
	g->out.chi[3] = 9;
	g->out.chi[4] = 9;
	g->out.chi[5] = 9;
	g->out.chi[6] = 9;
	g->out.chi[7] = 9;
	g->out.chi[8] = 9;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 57;
	g->kdesc[3] = 95;
	g->kdesc[4] = 105;
	g->kdesc[5] = 49;
	g->kdesc[6] = 54;
	g->kdesc[7] = 95;
	g->kdesc[8] = 105;
	g->kdesc[9] = 49;
	g->kdesc[10] = 54;
	g->kdesc[11] = 95;
	g->kdesc[12] = 102;
	g->kdesc[13] = 0;
	g->kname[8] = 52;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 9;
	t->im_ts = 36;
	t->im_oc = 4;
	t->im_ps = 4;
	t->im_pn = 1;
	t->im_pv = 1;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k875(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k875_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 53;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 63

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k876(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k876_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 63;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 54;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k877(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k877_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 15

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k878(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k878_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->itres = 15;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k879(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k879_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 57;
	t->ix_ab = 23;
	t->wo_ab = 41;
	t->vo_ab = 24;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 23
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k880(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 23) >> 23);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 41);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0xffffff);	/* Extract offset value */
				wo0 = (wo0 >> 24);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0xffffff);	/* Extract offset value */
				wo1 = (wo1 >> 24);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0xffffff);	/* Extract offset value */
				wo2 = (wo2 >> 24);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0xffffff);	/* Extract offset value */
				wo3 = (wo3 >> 24);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0xffffff);	/* Extract offset value */
				wo4 = (wo4 >> 24);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0xffffff);	/* Extract offset value */
				wo5 = (wo5 >> 24);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0xffffff);	/* Extract offset value */
				wo6 = (wo6 >> 24);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0xffffff);	/* Extract offset value */
				wo7 = (wo7 >> 24);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k880_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[7] = 56;
	g->kname[8] = 48;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k881(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k881_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[8] = 49;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 9
   Output channel 0 bits = 16
   Output channel 0 increment = 9
   Output channel 1 bits = 16
   Output channel 1 increment = 9
   Output channel 2 bits = 16
   Output channel 2 increment = 9
   Output channel 3 bits = 16
   Output channel 3 increment = 9
   Output channel 4 bits = 16
   Output channel 4 increment = 9
   Output channel 5 bits = 16
   Output channel 5 increment = 9
   Output channel 6 bits = 16
   Output channel 6 increment = 9
   Output channel 7 bits = 16
   Output channel 7 increment = 9
   Output channel 8 bits = 16
   Output channel 8 increment = 9
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 36)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 4 + (c) * 8))
#define IM_PE(p, v) *((unsigned int *)((p) + 32 + (v) * 4))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k882(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned int ova4;	/* Output value partial accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_PE(imp, vof) * vwe;	/* Accumulate last weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef IM_PE
#undef OT_E

void
imdi_k882_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 57;
	g->kdesc[4] = 95;
	g->kdesc[5] = 105;
	g->kdesc[6] = 49;
	g->kdesc[7] = 54;
	g->kdesc[8] = 95;
	g->kdesc[9] = 105;
	g->kdesc[10] = 49;
	g->kdesc[11] = 54;
	g->kdesc[12] = 95;
	g->kdesc[13] = 102;
	g->kname[8] = 50;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 1
   Input channel 0 bits = 16
   Input channel 0 increment = 1
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 10
   Interpolation table max resolution = 1024

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned int *)((p) + 0 + (off) * 4))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k883(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int wo0;	/* Weighting value and vertex offset variable */
			{
				unsigned int ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = (ti & 0x3fffff);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 22);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x1f);	/* Extract offset value */
				wo0 = (wo0 >> 5);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo0;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k883_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 1;
	g->od = 10;
	g->in.chi[0] = 1;
	g->out.chi[0] = 10;
	g->out.chi[1] = 10;
	g->out.chi[2] = 10;
	g->out.chi[3] = 10;
	g->out.chi[4] = 10;
	g->out.chi[5] = 10;
	g->out.chi[6] = 10;
	g->out.chi[7] = 10;
	g->out.chi[8] = 10;
	g->itres = 1024;
	g->stres = 0;
	g->kdesc[1] = 95;
	g->kdesc[2] = 49;
	g->kdesc[3] = 48;
	g->kname[8] = 51;
	t->it_xs = 0;
	t->wo_xs = 0;
	t->it_ab = 32;
	t->it_ts = 4;
	t->ix_ab = 10;
	t->wo_ab = 22;
	t->we_ab = 17;
	t->vo_ab = 5;
	t->vo_om = 5;
	t->im_ts = 40;
	t->im_oc = 8;
	t->im_fn = 5;
	t->im_ps = 0;
	t->im_pn = 0;
	t->im_pv = 0;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 3
   Input channel 0 bits = 16
   Input channel 0 increment = 3
   Input channel 1 bits = 16
   Input channel 1 increment = 3
   Input channel 2 bits = 16
   Input channel 2 increment = 3
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 322

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k884(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				CEX(wo0, wo1);
				CEX(wo0, wo2);
				CEX(wo1, wo2);
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo2;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k884_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 3;
	g->in.chi[0] = 3;
	g->in.chi[1] = 3;
	g->in.chi[2] = 3;
	g->itres = 322;
	g->stres = 0;
	g->kdesc[0] = 51;
	g->kname[8] = 52;
	t->it_ab = 64;
	t->it_ts = 8;
	t->ix_ab = 25;
	t->wo_ab = 39;
	t->vo_ab = 22;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 4
   Input channel 0 bits = 16
   Input channel 0 increment = 4
   Input channel 1 bits = 16
   Input channel 1 increment = 4
   Input channel 2 bits = 16
   Input channel 2 increment = 4
   Input channel 3 bits = 16
   Input channel 3 increment = 4
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 25
   Interpolation table max resolution = 76

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k885(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 25) >> 25);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 39);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x3fffff);	/* Extract offset value */
				wo0 = (wo0 >> 22);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x3fffff);	/* Extract offset value */
				wo1 = (wo1 >> 22);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x3fffff);	/* Extract offset value */
				wo2 = (wo2 >> 22);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x3fffff);	/* Extract offset value */
				wo3 = (wo3 >> 22);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo3;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k885_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 4;
	g->in.chi[0] = 4;
	g->in.chi[1] = 4;
	g->in.chi[2] = 4;
	g->in.chi[3] = 4;
	g->itres = 76;
	g->stres = 0;
	g->kdesc[0] = 52;
	g->kname[8] = 53;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 5
   Input channel 0 bits = 16
   Input channel 0 increment = 5
   Input channel 1 bits = 16
   Input channel 1 increment = 5
   Input channel 2 bits = 16
   Input channel 2 increment = 5
   Input channel 3 bits = 16
   Input channel 3 increment = 5
   Input channel 4 bits = 16
   Input channel 4 increment = 5
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 27

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k886(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo4;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k886_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 5;
	g->in.chi[0] = 5;
	g->in.chi[1] = 5;
	g->in.chi[2] = 5;
	g->in.chi[3] = 5;
	g->in.chi[4] = 5;
	g->itres = 27;
	g->stres = 0;
	g->kdesc[0] = 53;
	g->kname[8] = 54;
	t->ix_ab = 24;
	t->wo_ab = 40;
	t->vo_ab = 23;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 6
   Input channel 0 bits = 16
   Input channel 0 increment = 6
   Input channel 1 bits = 16
   Input channel 1 increment = 6
   Input channel 2 bits = 16
   Input channel 2 increment = 6
   Input channel 3 bits = 16
   Input channel 3 increment = 6
   Input channel 4 bits = 16
   Input channel 4 increment = 6
   Input channel 5 bits = 16
   Input channel 5 increment = 6
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 16

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k887(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo5;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k887_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 6;
	g->in.chi[0] = 6;
	g->in.chi[1] = 6;
	g->in.chi[2] = 6;
	g->in.chi[3] = 6;
	g->in.chi[4] = 6;
	g->in.chi[5] = 6;
	g->stres = 0;
	g->kdesc[0] = 54;
	g->kname[8] = 55;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 7
   Input channel 0 bits = 16
   Input channel 0 increment = 7
   Input channel 1 bits = 16
   Input channel 1 increment = 7
   Input channel 2 bits = 16
   Input channel 2 increment = 7
   Input channel 3 bits = 16
   Input channel 3 increment = 7
   Input channel 4 bits = 16
   Input channel 4 increment = 7
   Input channel 5 bits = 16
   Input channel 5 increment = 7
   Input channel 6 bits = 16
   Input channel 6 increment = 7
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 10

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k888(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo6;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k888_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 7;
	g->in.chi[0] = 7;
	g->in.chi[1] = 7;
	g->in.chi[2] = 7;
	g->in.chi[3] = 7;
	g->in.chi[4] = 7;
	g->in.chi[5] = 7;
	g->in.chi[6] = 7;
	g->itres = 10;
	g->stres = 0;
	g->kdesc[0] = 55;
	g->kname[8] = 56;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 8
   Input channel 0 bits = 16
   Input channel 0 increment = 8
   Input channel 1 bits = 16
   Input channel 1 increment = 8
   Input channel 2 bits = 16
   Input channel 2 increment = 8
   Input channel 3 bits = 16
   Input channel 3 increment = 8
   Input channel 4 bits = 16
   Input channel 4 increment = 8
   Input channel 5 bits = 16
   Input channel 5 increment = 8
   Input channel 6 bits = 16
   Input channel 6 increment = 8
   Input channel 7 bits = 16
   Input channel 7 increment = 8
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 24
   Interpolation table max resolution = 7

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp index, weighting and vertex offset */
#define IT_IT(p, off) *((unsigned longlong *)((p) + 0 + (off) * 8))

/* Sorting macros */
#define XFR(A, B) A = B;
#define CEX(A, B) if (A < B) { A ^= B; B ^= A; A ^= B; }
#define CXJ(A, B, D, L) if (A >= B) { D = B; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k889(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned longlong wo0;	/* Weighting value and vertex offset variable */
			unsigned longlong wo1;	/* Weighting value and vertex offset variable */
			unsigned longlong wo2;	/* Weighting value and vertex offset variable */
			unsigned longlong wo3;	/* Weighting value and vertex offset variable */
			unsigned longlong wo4;	/* Weighting value and vertex offset variable */
			unsigned longlong wo5;	/* Weighting value and vertex offset variable */
			unsigned longlong wo6;	/* Weighting value and vertex offset variable */
			unsigned longlong wo7;	/* Weighting value and vertex offset variable */
			{
				unsigned longlong ti;		/* Input table entry variable */
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti = IT_IT(it0, ip0[0]);
				wo0   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i  = (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it1, ip0[1]);
				wo1   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it2, ip0[2]);
				wo2   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it3, ip0[3]);
				wo3   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it4, ip0[4]);
				wo4   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it5, ip0[5]);
				wo5   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it6, ip0[6]);
				wo6   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				ti = IT_IT(it7, ip0[7]);
				wo7   = ((ti << 24) >> 24);	/* Extract weighting/vertex offset value */
				ti_i += (ti >> 40);	/* Extract interpolation table value */
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned longlong wot;	/* Sort temp variable */
					
					CEX(wo0, wo1);
					XFR(wot, wo2);
					CJ(wo1, wot, shs2);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs2);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs2:;
					XFR(wot, wo3);
					CJ(wo2, wot, shs3);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs3);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs3);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs3:;
					XFR(wot, wo4);
					CJ(wo3, wot, shs4);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs4);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs4);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs4);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs4:;
					XFR(wot, wo5);
					CJ(wo4, wot, shs5);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs5);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs5);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs5);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs5);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs5:;
					XFR(wot, wo6);
					CJ(wo5, wot, shs6);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs6);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs6);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs6);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs6);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs6);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs6:;
					XFR(wot, wo7);
					CJ(wo6, wot, shs7);
					XFR(wo7, wo6);
					CXJ(wo5, wot, wo6, shs7);
					XFR(wo6, wo5);
					CXJ(wo4, wot, wo5, shs7);
					XFR(wo5, wo4);
					CXJ(wo3, wot, wo4, shs7);
					XFR(wo4, wo3);
					CXJ(wo2, wot, wo3, shs7);
					XFR(wo3, wo2);
					CXJ(wo1, wot, wo2, shs7);
					XFR(wo2, wo1);
					CXJ(wo0, wot, wo1, shs7);
					XFR(wo1, wo0);
					XFR(wo0, wot);
shs7:;
				}
			}
			{
				unsigned int nvof;	/* Next vertex offset value */
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				nvof = (wo0 & 0x7fffff);	/* Extract offset value */
				wo0 = (wo0 >> 23);		/* Extract weighting value */
				vwe = 65536 - wo0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo1 & 0x7fffff);	/* Extract offset value */
				wo1 = (wo1 >> 23);		/* Extract weighting value */
				vwe = wo0 - wo1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo2 & 0x7fffff);	/* Extract offset value */
				wo2 = (wo2 >> 23);		/* Extract weighting value */
				vwe = wo1 - wo2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo3 & 0x7fffff);	/* Extract offset value */
				wo3 = (wo3 >> 23);		/* Extract weighting value */
				vwe = wo2 - wo3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo4 & 0x7fffff);	/* Extract offset value */
				wo4 = (wo4 >> 23);		/* Extract weighting value */
				vwe = wo3 - wo4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo5 & 0x7fffff);	/* Extract offset value */
				wo5 = (wo5 >> 23);		/* Extract weighting value */
				vwe = wo4 - wo5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo6 & 0x7fffff);	/* Extract offset value */
				wo6 = (wo6 >> 23);		/* Extract weighting value */
				vwe = wo5 - wo6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				nvof = (wo7 & 0x7fffff);	/* Extract offset value */
				wo7 = (wo7 >> 23);		/* Extract weighting value */
				vwe = wo6 - wo7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += nvof;			/* Move to next vertex */
				vwe = wo7;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_IT
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k889_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 8;
	g->in.chi[0] = 8;
	g->in.chi[1] = 8;
	g->in.chi[2] = 8;
	g->in.chi[3] = 8;
	g->in.chi[4] = 8;
	g->in.chi[5] = 8;
	g->in.chi[6] = 8;
	g->in.chi[7] = 8;
	g->itres = 7;
	g->stres = 0;
	g->kdesc[0] = 56;
	g->kname[8] = 57;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 9
   Input channel 0 bits = 16
   Input channel 0 increment = 9
   Input channel 1 bits = 16
   Input channel 1 increment = 9
   Input channel 2 bits = 16
   Input channel 2 increment = 9
   Input channel 3 bits = 16
   Input channel 3 increment = 9
   Input channel 4 bits = 16
   Input channel 4 increment = 9
   Input channel 5 bits = 16
   Input channel 5 increment = 9
   Input channel 6 bits = 16
   Input channel 6 increment = 9
   Input channel 7 bits = 16
   Input channel 7 increment = 9
   Input channel 8 bits = 16
   Input channel 8 increment = 9
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 11

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k890(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k890_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 9;
	g->in.chi[0] = 9;
	g->in.chi[1] = 9;
	g->in.chi[2] = 9;
	g->in.chi[3] = 9;
	g->in.chi[4] = 9;
	g->in.chi[5] = 9;
	g->in.chi[6] = 9;
	g->in.chi[7] = 9;
	g->in.chi[8] = 9;
	g->itres = 11;
	g->stres = 0;
	g->kdesc[0] = 57;
	g->kname[7] = 57;
	g->kname[8] = 48;
	t->it_xs = 1;
	t->wo_xs = 1;
	t->it_ts = 12;
	t->ix_ab = 32;
	t->we_ab = 32;
	t->vo_ab = 32;
}






/* Integer Multi-Dimensional Interpolation */
/* Interpolation Kernel Code */
/* Generated by cgen */
/* Copyright 2000 - 2007 Graeme W. Gill */
/* All rights reserved. */
/* This material is licenced under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3 :- */

/* see the License.txt file for licencing details.*/


/*
   Interpolation kernel specs:

   Input channels per pixel = 10
   Input channel 0 bits = 16
   Input channel 0 increment = 10
   Input channel 1 bits = 16
   Input channel 1 increment = 10
   Input channel 2 bits = 16
   Input channel 2 increment = 10
   Input channel 3 bits = 16
   Input channel 3 increment = 10
   Input channel 4 bits = 16
   Input channel 4 increment = 10
   Input channel 5 bits = 16
   Input channel 5 increment = 10
   Input channel 6 bits = 16
   Input channel 6 increment = 10
   Input channel 7 bits = 16
   Input channel 7 increment = 10
   Input channel 8 bits = 16
   Input channel 8 increment = 10
   Input channel 9 bits = 16
   Input channel 9 increment = 10
   Input is channel interleaved
   Input channels are separate words
   Input value extraction is done in input table lookup

   Output channels per pixel = 10
   Output channel 0 bits = 16
   Output channel 0 increment = 10
   Output channel 1 bits = 16
   Output channel 1 increment = 10
   Output channel 2 bits = 16
   Output channel 2 increment = 10
   Output channel 3 bits = 16
   Output channel 3 increment = 10
   Output channel 4 bits = 16
   Output channel 4 increment = 10
   Output channel 5 bits = 16
   Output channel 5 increment = 10
   Output channel 6 bits = 16
   Output channel 6 increment = 10
   Output channel 7 bits = 16
   Output channel 7 increment = 10
   Output channel 8 bits = 16
   Output channel 8 increment = 10
   Output channel 9 bits = 16
   Output channel 9 increment = 10
   Output is channel interleaved
   Output channels are separate words

   Basic Internal precision bits  = 16
   Weight+voffset bits       = 32
   Interpolation table index bits = 32
   Interpolation table max resolution = 9

   Processing direction is forwards
   Input stride is supported
   Output stride is supported
 */

/*
   Machine architecture specs:

   Little endian
   Reading and writing pixel values separately
   Pointer size = 64 bits

   Ordinal size  8 bits is known as 'unsigned char'
   Ordinal size 16 bits is known as 'unsigned short'
   Ordinal size 32 bits is known as 'unsigned int'
   Ordinal size 64 bits is known as 'unsigned longlong'
   Natural ordinal is 'unsigned int'

   Integer size  8 bits is known as 'signed char'
   Integer size 16 bits is known as 'short'
   Integer size 32 bits is known as 'int'
   Integer size 64 bits is known as 'longlong'
   Natural integer is 'int'

 */

#ifndef  IMDI_INCLUDED
#include <memory.h>
#include "imdi_utl.h"
#define  IMDI_INCLUDED
#endif  /* IMDI_INCLUDED */

#ifndef DEFINED_pointer
#define DEFINED_pointer
typedef unsigned char * pointer;
#endif

/* Input table interp. index */
#define IT_IX(p, off) *((unsigned int *)((p) + 0 + (off) * 12))

/* Input table input weighting enty */
#define IT_WE(p, off) *((unsigned int *)((p) + 4 + (off) * 12))

/* Input table input offset value enty */
#define IT_VO(p, off) *((unsigned int *)((p) + 8 + (off) * 12))

/* Sorting macros */
#define XFR(A, AA, B, BB) A = B; AA = BB;
#define CEX(A, AA, B, BB) if (A < B) { \
            A ^= B; B ^= A; A ^= B; AA ^= BB; BB ^= AA; AA ^= BB; }
#define CXJ(A, B, BB, D, DD, L) if (A >= B) { D = B; DD = BB; goto L; }
#define CJ(A, B, L) if (A >= B) goto L;

/* Interpolation multi-dim. table access */
#define IM_O(off) ((off) * 40)

/* Interpolation table - get vertex values */
#define IM_FE(p, v, c) *((unsigned longlong *)((p) + (v) * 8 + (c) * 8))

/* Output table indexes */
#define OT_E(p, off) *((unsigned short *)((p) + (off) * 2))

void
imdi_k891(
imdi *s,			/* imdi context */
void **outp,		/* pointer to output pointers */
int  ostride,		/* optional input component stride */
void **inp,		/* pointer to input pointers */
int  istride,		/* optional input component stride */
unsigned int npix	/* Number of pixels to process */
) {
	imdi_imp *p = (imdi_imp *)(s->impl);
	unsigned short *ip0 = (unsigned short *)inp[0];
	unsigned short *op0 = (unsigned short *)outp[0];
	unsigned short *ep = (unsigned short *)inp[0] + npix * istride ;
	pointer it0 = (pointer)p->in_tables[0];
	pointer it1 = (pointer)p->in_tables[1];
	pointer it2 = (pointer)p->in_tables[2];
	pointer it3 = (pointer)p->in_tables[3];
	pointer it4 = (pointer)p->in_tables[4];
	pointer it5 = (pointer)p->in_tables[5];
	pointer it6 = (pointer)p->in_tables[6];
	pointer it7 = (pointer)p->in_tables[7];
	pointer it8 = (pointer)p->in_tables[8];
	pointer it9 = (pointer)p->in_tables[9];
	pointer ot0 = (pointer)p->out_tables[0];
	pointer ot1 = (pointer)p->out_tables[1];
	pointer ot2 = (pointer)p->out_tables[2];
	pointer ot3 = (pointer)p->out_tables[3];
	pointer ot4 = (pointer)p->out_tables[4];
	pointer ot5 = (pointer)p->out_tables[5];
	pointer ot6 = (pointer)p->out_tables[6];
	pointer ot7 = (pointer)p->out_tables[7];
	pointer ot8 = (pointer)p->out_tables[8];
	pointer ot9 = (pointer)p->out_tables[9];
	pointer im_base = (pointer)p->im_table;
	
	for(;ip0 != ep; ip0 += istride, op0 += ostride) {
		unsigned longlong ova0;	/* Output value accumulator */
		unsigned longlong ova1;	/* Output value accumulator */
		unsigned longlong ova2;	/* Output value accumulator */
		unsigned longlong ova3;	/* Output value accumulator */
		unsigned longlong ova4;	/* Output value accumulator */
		{
			pointer imp;
			unsigned int we0;	/* Weighting value variable */
			unsigned int vo0;	/* Vertex offset variable */
			unsigned int we1;	/* Weighting value variable */
			unsigned int vo1;	/* Vertex offset variable */
			unsigned int we2;	/* Weighting value variable */
			unsigned int vo2;	/* Vertex offset variable */
			unsigned int we3;	/* Weighting value variable */
			unsigned int vo3;	/* Vertex offset variable */
			unsigned int we4;	/* Weighting value variable */
			unsigned int vo4;	/* Vertex offset variable */
			unsigned int we5;	/* Weighting value variable */
			unsigned int vo5;	/* Vertex offset variable */
			unsigned int we6;	/* Weighting value variable */
			unsigned int vo6;	/* Vertex offset variable */
			unsigned int we7;	/* Weighting value variable */
			unsigned int vo7;	/* Vertex offset variable */
			unsigned int we8;	/* Weighting value variable */
			unsigned int vo8;	/* Vertex offset variable */
			unsigned int we9;	/* Weighting value variable */
			unsigned int vo9;	/* Vertex offset variable */
			{
				unsigned int ti_i;	/* Interpolation index variable */
				
				ti_i  = IT_IX(it0, ip0[0]);
				we0   = IT_WE(it0, ip0[0]);
				vo0   = IT_VO(it0, ip0[0]);
				ti_i += IT_IX(it1, ip0[1]);
				we1   = IT_WE(it1, ip0[1]);
				vo1   = IT_VO(it1, ip0[1]);
				ti_i += IT_IX(it2, ip0[2]);
				we2   = IT_WE(it2, ip0[2]);
				vo2   = IT_VO(it2, ip0[2]);
				ti_i += IT_IX(it3, ip0[3]);
				we3   = IT_WE(it3, ip0[3]);
				vo3   = IT_VO(it3, ip0[3]);
				ti_i += IT_IX(it4, ip0[4]);
				we4   = IT_WE(it4, ip0[4]);
				vo4   = IT_VO(it4, ip0[4]);
				ti_i += IT_IX(it5, ip0[5]);
				we5   = IT_WE(it5, ip0[5]);
				vo5   = IT_VO(it5, ip0[5]);
				ti_i += IT_IX(it6, ip0[6]);
				we6   = IT_WE(it6, ip0[6]);
				vo6   = IT_VO(it6, ip0[6]);
				ti_i += IT_IX(it7, ip0[7]);
				we7   = IT_WE(it7, ip0[7]);
				vo7   = IT_VO(it7, ip0[7]);
				ti_i += IT_IX(it8, ip0[8]);
				we8   = IT_WE(it8, ip0[8]);
				vo8   = IT_VO(it8, ip0[8]);
				ti_i += IT_IX(it9, ip0[9]);
				we9   = IT_WE(it9, ip0[9]);
				vo9   = IT_VO(it9, ip0[9]);
				
				imp = im_base + IM_O(ti_i);		/* Compute interp. table entry pointer */
				
				/* Sort weighting values and vertex offset values */
				{
					unsigned int wet;	/* Sort temporary */
					unsigned int vot;	/* Sort temporary */
					
					CEX(we0, vo0, we1, vo1);
					XFR(wet, vot, we2, vo2);
					CJ(we1, wet, shs2);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs2);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs2:;
					XFR(wet, vot, we3, vo3);
					CJ(we2, wet, shs3);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs3);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs3);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs3:;
					XFR(wet, vot, we4, vo4);
					CJ(we3, wet, shs4);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs4);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs4);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs4);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs4:;
					XFR(wet, vot, we5, vo5);
					CJ(we4, wet, shs5);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs5);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs5);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs5);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs5);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs5:;
					XFR(wet, vot, we6, vo6);
					CJ(we5, wet, shs6);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs6);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs6);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs6);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs6);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs6);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs6:;
					XFR(wet, vot, we7, vo7);
					CJ(we6, wet, shs7);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs7);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs7);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs7);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs7);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs7);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs7);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs7:;
					XFR(wet, vot, we8, vo8);
					CJ(we7, wet, shs8);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs8);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs8);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs8);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs8);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs8);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs8);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs8);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs8:;
					XFR(wet, vot, we9, vo9);
					CJ(we8, wet, shs9);
					XFR(we9, vo9, we8, vo8);
					CXJ(we7, wet, vot, we8, vo8, shs9);
					XFR(we8, vo8, we7, vo7);
					CXJ(we6, wet, vot, we7, vo7, shs9);
					XFR(we7, vo7, we6, vo6);
					CXJ(we5, wet, vot, we6, vo6, shs9);
					XFR(we6, vo6, we5, vo5);
					CXJ(we4, wet, vot, we5, vo5, shs9);
					XFR(we5, vo5, we4, vo4);
					CXJ(we3, wet, vot, we4, vo4, shs9);
					XFR(we4, vo4, we3, vo3);
					CXJ(we2, wet, vot, we3, vo3, shs9);
					XFR(we3, vo3, we2, vo2);
					CXJ(we1, wet, vot, we2, vo2, shs9);
					XFR(we2, vo2, we1, vo1);
					CXJ(we0, wet, vot, we1, vo1, shs9);
					XFR(we1, vo1, we0, vo0);
					XFR(we0, vo0, wet, vot);
shs9:;
				}
			}
			{
				unsigned int vof;	/* Vertex offset value */
				unsigned int vwe;	/* Vertex weighting */
				
				vof = 0;				/* First vertex offset is 0 */
				vwe = 65536 - we0;		/* Baricentric weighting */
				ova0  = IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1  = IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2  = IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3  = IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4  = IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo0;			/* Move to next vertex */
				vwe = we0 - we1;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo1;			/* Move to next vertex */
				vwe = we1 - we2;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo2;			/* Move to next vertex */
				vwe = we2 - we3;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo3;			/* Move to next vertex */
				vwe = we3 - we4;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo4;			/* Move to next vertex */
				vwe = we4 - we5;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo5;			/* Move to next vertex */
				vwe = we5 - we6;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo6;			/* Move to next vertex */
				vwe = we6 - we7;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo7;			/* Move to next vertex */
				vwe = we7 - we8;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo8;			/* Move to next vertex */
				vwe = we8 - we9;		/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
				vof += vo9;			/* Move to next vertex */
				vwe = we9;				/* Baricentric weighting */
				ova0 += IM_FE(imp, vof, 0) * vwe;	/* Accumulate weighted output values */
				ova1 += IM_FE(imp, vof, 1) * vwe;	/* Accumulate weighted output values */
				ova2 += IM_FE(imp, vof, 2) * vwe;	/* Accumulate weighted output values */
				ova3 += IM_FE(imp, vof, 3) * vwe;	/* Accumulate weighted output values */
				ova4 += IM_FE(imp, vof, 4) * vwe;	/* Accumulate weighted output values */
			}
		}
		{
			unsigned int oti;	/* Vertex offset value */
			oti = ((ova0 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[0] = OT_E(ot0, oti);	/* Write result */
			oti = ((ova0 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[1] = OT_E(ot1, oti);	/* Write result */
			oti = ((ova1 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[2] = OT_E(ot2, oti);	/* Write result */
			oti = ((ova1 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[3] = OT_E(ot3, oti);	/* Write result */
			oti = ((ova2 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[4] = OT_E(ot4, oti);	/* Write result */
			oti = ((ova2 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[5] = OT_E(ot5, oti);	/* Write result */
			oti = ((ova3 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[6] = OT_E(ot6, oti);	/* Write result */
			oti = ((ova3 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[7] = OT_E(ot7, oti);	/* Write result */
			oti = ((ova4 >> 16) & 0xffff);	/* Extract integer part of result */
			op0[8] = OT_E(ot8, oti);	/* Write result */
			oti = ((ova4 >> 48) & 0xffff);	/* Extract integer part of result */
			op0[9] = OT_E(ot9, oti);	/* Write result */
		}
	}
}
#undef IT_WE
#undef IT_VO
#undef IT_IX
#undef CXJ
#undef CJ
#undef XFR
#undef CEX
#undef IM_O
#undef IM_FE
#undef OT_E

void
imdi_k891_gentab(
genspec *g,		/* structure to be updated */
tabspec *t		/* structure to be updated */
) {
	g->id = 10;
	g->in.chi[0] = 10;
	g->in.chi[1] = 10;
	g->in.chi[2] = 10;
	g->in.chi[3] = 10;
	g->in.chi[4] = 10;
	g->in.chi[5] = 10;
	g->in.chi[6] = 10;
	g->in.chi[7] = 10;
	g->in.chi[8] = 10;
	g->itres = 9;
	g->stres = 0;
	g->kdesc[0] = 49;
	g->kdesc[1] = 48;
	g->kdesc[2] = 95;
	g->kdesc[3] = 49;
	g->kdesc[4] = 48;
	g->kdesc[5] = 95;
	g->kdesc[6] = 105;
	g->kdesc[7] = 49;
	g->kdesc[8] = 54;
	g->kdesc[9] = 95;
	g->kdesc[10] = 105;
	g->kdesc[11] = 49;
	g->kdesc[12] = 54;
	g->kdesc[13] = 95;
	g->kdesc[14] = 102;
	g->kname[8] = 49;
}






